
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="modal" id="addLineDiv" tabindex="-1" role="dialog" aria-hidden="true">

	<div class="modal-dialog" role="document">

		<div class="modal-content animated bounceInRight">

			<div class="modal-header">
				<h4 class="modal-title">期间行编辑</h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			</div>

			<div class="modal-body" style="padding-bottom: 20px;">
				<%-- 导入提示信息框 --%>
			    <c:if test="${hint!=null&&hint!=''}">
			   		<jsp:include page="../../common/alert/alert.jsp">
			   			<jsp:param value="${hint}" name="alertType"/>
			   			<jsp:param value="${alertMessage}" name="alertMessage"/>
			   		</jsp:include>
			    </c:if>
			
				<form id="cform">
					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>期间名称</label>
						<div class="col-sm-9">
							<input id="periodName" name="periodName" type="text" class="form-control" value="${requestScope.mdFinanceCalendarPeriod.periodName}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					
					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>期间年度</label>
						<div class="col-sm-9">
							<input id="periodYear" name="periodYear" type="text" class="form-control" value="${requestScope.mdFinanceCalendarPeriod.periodYear}">
							<span class="help-block m-b-none" style="color: gray;">填写期间所在年份</span>
						</div>
					</div>
					<div class="hr-line-dashed"></div>

					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>期间季度</label>
						<div class="col-sm-9">
							<input id="periodQuarter" name="periodQuarter" type="text" class="form-control" value="${requestScope.mdFinanceCalendarPeriod.periodQuarter}">
							<span class="help-block m-b-none" style="color: gray;">填写期间所在季度，数字1-4，表示1-4季度</span>
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					
					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>开始日期</label>
						<div class="col-sm-9">
							<div class="input-group date">
								<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input id="periodStartDate" name="periodStartDate" type="text" class="form-control" value="<fmt:formatDate value="${requestScope.mdFinanceCalendarPeriod.periodStartDate}" pattern="yyyy-MM-dd"/>" autocomplete="off">
							</div>
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					
					<div class="form-group row">
						<label class="col-sm-3 col-form-label">结束日期</label>
						<div class="col-sm-9">
							<div class="input-group date">
								<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input id="periodEndDate" name="periodEndDate" type="text" class="form-control" value="<fmt:formatDate value="${requestScope.mdFinanceCalendarPeriod.periodEndDate}" pattern="yyyy-MM-dd"/>" autocomplete="off">
							</div>
						</div>
					</div>
					<div class="hr-line-dashed"></div>

					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>期间状态</label>
						<div class="col-sm-9">
							<select class="form-control m-b" name="periodStatus" id="periodStatus">
								<option value="CLOSE" selected="selected">关闭</option>
								<option value="OPEN">打开</option>
							</select>
						</div>
					</div>
					<div class="hr-line-dashed"></div>


					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>调整期间</label>
						<div class="col-sm-9">
							<select class="form-control m-b" name="adjustFlag" id="adjustFlag">
								<option value="N" selected="selected">否</option>
								<option value="Y">是</option>
							</select>
						</div>
					</div>
					<div class="hr-line-dashed"></div>

					<div class="form-group row m-b-none">
						<div class="col-sm-12 col-sm-offset-2 text-right">
							<button class="btn btn-white btn-lg" type="button"
								data-dismiss="modal">返回</button>
							&nbsp;
							<button
								class="ladda-button ladda-button-demo btn btn-primary btn-lg"
								data-style="expand-right">
								&nbsp;&nbsp;确定&nbsp;&nbsp;<i class="fa fa-check-square-o"></i>
							</button>
						</div>
					</div>
					
					<input type="hidden" id="calendarCode" name="calendarCode" value="${param.calendarCode}"> 
					<input type="hidden" id="periodId" name="periodId" value="${requestScope.mdFinanceCalendarPeriod.periodId}"> 
					<input type="hidden" id="createdDate" name="createdDate" value="${requestScope.mdFinanceCalendarPeriod.createdDate}"> 
					<input type="hidden" id="createdBy" name="createdBy" value="${requestScope.mdFinanceCalendarPeriod.createdBy}">
				</form>
			</div>

		</div>

	</div>

</div>

<script>
	$(document).ready(function() {
		//初始化periodStatus
		if("${requestScope.mdFinanceCalendarPeriod.periodStatus}"!=""){
			$("#periodStatus").val("${requestScope.mdFinanceCalendarPeriod.periodStatus}");
		}
		//初始化adjustFlag
		if("${requestScope.mdFinanceCalendarPeriod.adjustFlag}"!=""){
			$("#adjustFlag").val("${requestScope.mdFinanceCalendarPeriod.adjustFlag}");
		}
		
		//设置日期插件
		$('#periodStartDate').datepicker({
			todayBtn : "linked",
			keyboardNavigation : true,
			forceParse : true,
			calendarWeeks : false,
			autoclose : true,
			format: 'yyyy-mm-dd',
			language: 'zh-CN',
		});
		
		$('#periodEndDate').datepicker({
			todayBtn : "linked",
			keyboardNavigation : true,
			forceParse : true,
			calendarWeeks : false,
			autoclose : true,
			format: 'yyyy-mm-dd',
			language: 'zh-CN',
		});
		
		
		
		//表单提交
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#cform").valid();
			//l.ladda('stop');
		});

		$("#cform").validate({
			rules : {
				periodName : {
					required : true,
				},
				periodYear : {
					required : true,
					gtZero : true,
					digits:true,
					range:[2000,2100]
				},
				periodQuarter : {
					required : true,
					gtZero : true,
					digits:true,
					range:[1,4]
				},
				periodStartDate : {
					required : true,
				},
				periodEndDate : {
					required : true,
				},
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
				
				if(submitFlag=="Y"){
					l.ladda('start');
					editLine();
				}
		    }
		});
		
	});
	
	//异步编辑行
	function editLine(){
		redragonJS.loading("tabDiv");
	
		$.ajax({
			type: "post",
			url: "web/mdFinanceCalendarPeriod/editMdFinanceCalendarPeriod",
			data: {"calendarCode": $("#calendarCode").val(), "periodName": $("#periodName").val(), "periodYear": $("#periodYear").val(), "periodQuarter": $("#periodQuarter").val(), 
				   "periodStartDate": $("#periodStartDate").val(), "periodEndDate": $("#periodEndDate").val(), "periodStatus": $("#periodStatus").val(), "adjustFlag": $("#adjustFlag").val(),
				   "periodId": $("#periodId").val(), "createdDate": $("#createdDate").val(), "createdBy": $("#createdBy").val()},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				redragonJS.removeLoading("tabDiv");
				$('#addLineDiv').modal('hide');
				$('.ladda-button-demo').ladda('stop');
				
				var json = JSON.parse(data);
				if(json.result=="success"){
					getLineTab($("#calendarCode").val());
				}else{
					redragonJS.alert("编辑期间行错误");
				}
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	
</script>
